package org.alvin.dispatchtcp;

public class BikeByteUtils {

    /**
     * 大小端互转通用方法
     * @param bytes
     * @return
     */

    public static byte[] convertEndian(byte[] bytes) {
        for (int i = 0; i < bytes.length / 2; i++) {
            byte temp = bytes[i];
            bytes[i] = bytes[bytes.length - i - 1];
            bytes[bytes.length - i - 1] = temp;
        }
        return bytes;
    }


    /**
     * 求字节数组的校验和
     *
     * @param buff 需要求校验和的字节数组
     * @return 校验和
     */
    public static int sumCheck(byte[] buff ,int start ,int end) {
        int sum = 0;
        for (int i = start ;i <= end;i++) {
            sum += buff[i] & 0xFF;
        }
        return sum ;
    }

    /*两个字节十六进制转无符号整型*/
    public static int bytes2ToInt(byte[] src) {
        int value;
        value = (int) ((src[0] & 0xFF) | ((src[0 + 1] & 0xFF) << 8));
        return value;
    }
}
